import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA03Y4ZKi0NvCL6PCBCzx2
NOMph/b/C4FAjut/A1KrYvIsSGNd03HKNJz6rET0RcPXRGZ7lOK053pPWCH6zCiC
mjVYdXlbzr2QSiubdMWXRPvfyOHfY9s9m7Bp0ML3HptVelLCO0AGibYT0gXxSzlB
mSFk9VqmBtmSvVM27dXbETfNd2Enml6tY8DJqk/akxpgE6AtytUYVkwO+rvTrUUX
iOkCfnROOa5zkDMH7rgtjz1QOB1PkO5wkK2ERVp5CyeDKOj0Lj53M86fp8//cRrg
dd2VGWLi1vNqhmbnXV0tu14mP5uGxOxvR9SAkwXJHnhHlGc2bPRx2yGk7D6AybAK
zQIDAQAB`

const privateKey = `MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDTdjhkqLQ28Ivo
8IELPHY04ymH9v8LgUCO638DUqti8ixIY13Tcco0nPqsRPRFw9dEZnuU4rTnek9Y
IfrMKIKaNVh1eVvOvZBKK5t0xZdE+9/I4d9j2z2bsGnQwvcem1V6UsI7QAaJthPS
BfFLOUGZIWT1WqYG2ZK9Uzbt1dsRN813YSeaXq1jwMmqT9qTGmAToC3K1RhWTA76
u9OtRReI6QJ+dE45rnOQMwfuuC2PPVA4HU+Q7nCQrYRFWnkLJ4Mo6PQuPnczzp+n
z/9xGuB13ZUZYuLW82qGZuddXS27XiY/m4bE7G9H1ICTBckeeEeUZzZs9HHbIaTs
PoDJsArNAgMBAAECggEAEtB27gXQmv7GBAC6Cozjm4sGm/FO+fATFWRAlcQaOaCA
biRhKbn7GrlI2GD+NuLY2V4g6rtNCzdnrdjAHsAP9rZ+W11j3L4jA2Zj23zlG58p
Zw8puBG+poaIs6lVIWUCsvKAE5N7wW7wzoP21xGOE5jUCbx5/ywGkU/BGGIprptW
AVWBxutetMIAowOO/Oxq783eqysctXxYwVXf4ezUeWaOaHgWgyuoZ6uC0oxZhqU3
AR54sMysx1FblQkbISCEMP7L9IbQGS5PvtHYiFJtRqasjH0DIIRjHBeZL2kxpews
okrhk5CVfRVQUnfw2dfPInv+ffpNPs0Cptxg2edlJQKBgQDwE1g5Gpu+4XJgK6aJ
N1KfkjDQwmAy1Njw1px2aXdlJaubFouu4JpqddYQR/h+Miysuqr729oF+KSdhyGX
BKAZPMBRn812/tp35HObdPI9RvLCd2ofl6op6NBx0v4V/mnWvF06h8WrDGhVN1OL
5UgtAyHoR0Gtj5rnW6O0ZpIIKwKBgQDhfP5NWvbMQkOjckWoRA4A26osTHjw5O6b
aT4WSDTaHCi73+sgMVacj0gBAApceXAZiAGiuKns8Wp1dJDyFXi8cC0owSjtl5Ye
JH4uPXHXgza5B6vF8ite40ZpSoT6iY0oSVsxIYd7rLOgSDxNCb5OtjAOntYknUNU
Px5u3F4E5wKBgQDFDCuqWxOgXWzCULGVCGpxfM1CW3gX4KnbK1squa/8vimW1q95
rvIvFV7I6DmmYspWT7SNmkreAdIjVcmVKX+6lymHFXHQDKgGJeVZoGg/MV+Ji/f3
zEUntuZ3tmVEahg2305p/wyYM0vjPdD+DwfpohuPigT3TtomsQmxxUpxFwKBgQCb
enlK028bNpG28MNRG+Pf+ZckRnKZ//D63h1+dbljr0jzCpnwr7R97VoDvohmbSG7
qQkfr18Tzv7OEFslYWLH5D1vPYlAEmbjT9xle960cHhaKwzpR2taWTIixcxdiFz5
q2MixHDL+TA+U7ComhBL69nFKwaTZpCXVZJhdLerfwKBgGSfA3GIjsmUABajVKFl
e57ujBITLyxfmbO2iHEBqIGT+WxvfHFVcnLNREUN4jWGlVE6uDvEaMVu1sp+4VT7
1P5em8x33M0GiYKv2gflpRQpoinvG+h41b3fjdgzwpaiPtorvwbScgvDIAnHyqZA
QuCZB3GVLRNtPDyQ3wx6HmTT`

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
